namespace = cr_law_init

# New-game initialization for Carnal Realms gender-policy laws.
# Runs once from on_chronicle_start. The global flag also prevents the
# Ruler Designer double-fire from applying the setup twice.
character_event = {
	id = cr_law_init.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = cr_law_initialization_complete }
	}

	immediate = {
		# Initialize the player ruler, because any_playable_ruler excludes ROOT.
		if = {
			limit = { is_ruler = yes }

			# Catholic baseline: 2 / 2 / 2.
			if = {
				limit = {
					religion = catholic
					higher_tier_than = COUNT
				}
				primary_title = {
					add_law = {
						law = cr_female_authority_law_2
						cooldown = no
						opinion_effect = no
					}
					add_law = {
						law = cr_ordination_law_2
						cooldown = no
						opinion_effect = no
					}
					add_law = {
						law = cr_councilor_gender_law_2
						cooldown = no
						opinion_effect = no
					}
				}
			}

			# A female starting ruler begins with Absolute Cognatic succession.
			if = {
				limit = {
					is_female = yes
					is_patrician = no
				}
				primary_title = {
					gender_succ = true_cognatic
				}
				recalc_succession = yes
			}
		}

		# Initialize every other playable ruler.
		any_playable_ruler = {
			# Catholic baseline: 2 / 2 / 2.
			if = {
				limit = {
					religion = catholic
					higher_tier_than = COUNT
				}
				primary_title = {
					add_law = {
						law = cr_female_authority_law_2
						cooldown = no
						opinion_effect = no
					}
					add_law = {
						law = cr_ordination_law_2
						cooldown = no
						opinion_effect = no
					}
					add_law = {
						law = cr_councilor_gender_law_2
						cooldown = no
						opinion_effect = no
					}
				}
			}

			# A female starting ruler begins with Absolute Cognatic succession.
			if = {
				limit = {
					is_female = yes
					is_patrician = no
				}
				primary_title = {
					gender_succ = true_cognatic
				}
				recalc_succession = yes
			}
		}

		set_global_flag = cr_law_initialization_complete
	}
}
